package com.imooc.controller;

import com.imooc.vo.TestVo;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//@Controller
@Api  //忽略swagger2的扫描
@RestController // 默认返回json对象
public class HelloController {
    @GetMapping("hello")
    public String hello() {
        return "Hello World";
    }


    @PostMapping("testBody")
    public TestVo testBody(@RequestBody TestVo testVo) {
        return testVo;
    }


    @RequestMapping("testParam")
    public TestVo testParam(String name) {
        TestVo testVo = new TestVo();
        testVo.setName(name);
        testVo.setAge("30");
        return testVo;
    }


    @RequestMapping("testMultiParam")
    public TestVo testMultiParam(String name,String age) {
        TestVo testVo = new TestVo();
        testVo.setName(name);
        testVo.setAge(age);
        return testVo;
    }


    @RequestMapping("testTransaction")
    public TestVo testTransaction(String name,String age){
        TestVo testVo = new TestVo();
        testVo.setName(name);
        testVo.setAge(age);
        return testVo;
    }


    @RequestMapping("testException")
    public TestVo testException(){
        throw new RuntimeException();

    }




}
